package com.lannuokeji.base;

import java.util.HashMap;
import java.util.Map;

import org.apache.shiro.SecurityUtils;

/**
 * 控制器基础类
 * 
 * @author 览诺科技
 *
 */
public abstract class AController {

	public static final int SUCCESS = 0;
	public static final int LOGIN = 1;
	public static final int UNAUTHORIZED = 2;
	public static final int ERROR = 3;

	public Map<String, Object> ret = new HashMap<String, Object>(); // 获取返回对象，自定义

	/**
	 * 设置返回码
	 * 
	 * @param code 返回码
	 * @return
	 */
	public Map<String, Object> setReturnCode(int code) {
		ret.put("code", code);
		return ret;
	}

	/**
	 * 设置返回对象
	 * @param content
	 * @return
	 */
	public Map<String, Object> setReturnContent(Object content) {
		ret.put("content", content);
		return ret;
	}
	
	/**
	 * 设置返回code和content
	 * @param content
	 * @return
	 */
	public Map<String, Object> setReturn(int code, Object content) {
		setReturnCode(code);
		setReturnContent(content);
		return ret;
	}
	/**
	 * 设置成功时的返回对象
	 * @param content
	 * @return
	 */
	public Map<String, Object> setSuccessContent(Object content) {
		setReturn(SUCCESS, content);
		return ret;
	}
	/**
	 * 设置错误时的返回对象
	 * @param content
	 * @return
	 */
	public Map<String, Object> setErrorContent(Object content) {
		setReturn(ERROR, content);
		return ret;
	}
	
	public String getUser() {
		String userId = (String) SecurityUtils.getSubject().getPrincipal();
		return userId;
	}

}
